﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace WpfWordsLearner.Model
{
	public class NotifierBase : System.ComponentModel.INotifyPropertyChanged
	{
		public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

		protected void OnPropertyChanged(string propName)
		{
			System.ComponentModel.PropertyChangedEventHandler handler = System.Threading.Interlocked.CompareExchange(ref PropertyChanged, null, null);
			if (System.ComponentModel.TypeDescriptor.GetProperties(this.GetType()).Find(propName, false) == null)
			{
				throw new InvalidOperationException(string.Format("Could't found propersty name: {0}", propName));
			}
			if (handler != null)
			{
				handler(this, new System.ComponentModel.PropertyChangedEventArgs(propName));
			}
		}
	}

	public interface IBaseIO
	{
		string Name { get; set; }
	}

	public class DirectoryModel : NotifierBase, IBaseIO
	{
		public DirectoryModel()
			: base()
		{
			Children = new ObservableCollection<IBaseIO>();
		}

		private string myVar;
		public string Name
		{
			get { return myVar; }
			set { myVar = value; base.OnPropertyChanged("Name"); }
		}

		private string folPath;
		public string FullPath
		{
			get { return folPath; }
			set { folPath = value; base.OnPropertyChanged("FullPath"); }
		}

		ObservableCollection<IBaseIO> folders;
		public ObservableCollection<IBaseIO> Children
		{
			get { return folders; }
			set { folders = value; OnPropertyChanged("Children"); }
		}
	}

	public class FileModel : NotifierBase, IBaseIO
	{
		public FileModel() : base() { }

		private string fname;
		public string Name
		{
			get { return fname; }
			set { fname = value; OnPropertyChanged("Name"); }
		}

		private long len;
		public long Lenght
		{
			get { return len; }
			set { len = value; OnPropertyChanged("Lenght"); }
		}

		private string fullPath;
		public string FullPath
		{
			get { return fullPath; }
			set { fullPath = value; OnPropertyChanged("FullPath"); }
		}
	}
}
